package com.weixing.mall.provider.controller.rpc;

import com.weixing.mall.base.wrapper.Result;
import com.weixing.mall.base.wrapper.ResultUtil;
import com.weixing.mall.core.support.BaseController;
import com.weixing.mall.provider.api.model.vo.ItemVo;
import com.weixing.mall.provider.service.IShopCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CartRpcController
 * @Description
 * @Author Small
 * @Date 2020/1/16 18:29
 * @Version 1.0
 **/
@RestController
@RequestMapping("api/cart")
public class CartRpcController extends BaseController {
    @Autowired
    private IShopCartService shopCartService;

    @GetMapping("loadSelectedItem")
    public Result<List<ItemVo>> loadSelectedItem(Long memberId){
        List<ItemVo> vos = shopCartService.loadSelectedItem(memberId);
        return ResultUtil.success(vos);
    }

//    @PostMapping("removeItemFromCart")
//    public Result removeItemFromCart(String cartItemIdsJsonStr){
//        List<Long> aLongs = JSONArray.parseArray(cartItemIdsJsonStr, Long.class);
//        shopCartService.removeByIds(aLongs);
//        return ResultUtil.success();
//    }

    @PostMapping("removeItemFromCart")
    public Result removeItemFromCart(@RequestBody List<Long> cartItemIds){
        shopCartService.removeByIds(cartItemIds);
        return ResultUtil.success();
    }
}
